package com.troy.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.troy.dao.UserDao;
import com.troy.entity.User;
import com.troy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;


    @Override
    @DS("slave_1")
    public List<User> selectAll() {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        return userDao.selectList(queryWrapper);
    }

    @Override
    public void save(User user) {
        userDao.insert(user);
    }

    @Override
    public User queryByid(Integer id) {
        User user = userDao.selectById(id);
        return user;
    }

    @Override
    public void update(User user) {

        userDao.updateById(user);
    }

    @Override
    public void delete(String id) {
        userDao.deleteById(id);
    }

    @Override
    public User test1(String id) {

        return  userDao.selectTest(id);
    }

}
